package Servlet_Four;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.staff.Util.JDBC_Staff;
import com.staff.model.user;

@WebServlet("/LoginServlet_Four")
public class LoginServlet_Four extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public LoginServlet_Four() {
		super();
		// TODO Auto-generated constructor stub
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		user list = new user();
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		Object[] obs = { username };
		String sql = "select * from user where username=?";
		list = JDBC_Staff.getSingleResult(sql, obs, user.class);
		if (list != null) {
			if (list.getUsername().equals(username) && list.getPassword().equals(password)) {
				// request.getRequestDispatcher("/showEmployee_Four.jsp").forward(request,response);
				response.sendRedirect("/Java_web/showEmployee_Four.jsp");
			}
		}

	}
}
